<template>
  <div>
    <div class="expricingIndex" v-show="exPricingShow === 'expricingIndex'">
      <el-row>
        <el-col :span="8" :offset="8">
          <el-row>
            <el-form
              :model="saveForm"
              label-width="150px"
              label-position="right"
              :rules="saveFormRules"
              ref="expricingForm"
            >
              <el-col :span="24">
                <el-form-item label="任务编号: " prop="taskCode" required>
                  <el-input v-model="saveForm.taskCode" disabled></el-input>
                </el-form-item>
              </el-col>

              <el-col :span="24">
                <el-form-item label="任务名称: " prop="taskName">
                  <el-input v-model="saveForm.taskName" disabled></el-input>
                </el-form-item>
              </el-col>

              <el-col :span="24">
                <el-form-item label="数据开始日期: " prop="startDataDate">
                  <el-date-picker
                    v-model="saveForm.startDataDate"
                    style="width:100%"
                    format="yyyy-MM-dd"
                     value-format="yyyy-MM-dd"
                    placeholder="选择数据开始日期"
                  ></el-date-picker>
                </el-form-item>
              </el-col>

              <el-col :span="24">
                <el-form-item label="数据结束日期: " prop="endDataDate">
                  <el-date-picker
                    v-model="saveForm.endDataDate"
                    format="yyyy-MM-dd"
                    value-format="yyyy-MM-dd"
                    style="width:100%"
                    placeholder="选择数据结束日期"
                  ></el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="定价情景: " prop="sceneName">
                  <el-input v-model="saveForm.scene.sceneName" disabled></el-input>
                </el-form-item>
              </el-col>
              <el-col>
                <el-row>
                  <el-col :span="8">
                    <el-button size="medium" @click="execute" :disabled="executebutton">执行定价</el-button>
                  </el-col>
                  <el-col :span="8">
                    <el-button size="medium" @click="exmonitor">执行监控</el-button>
                  </el-col>
                  <el-col :span="8">
                    <el-button size="medium" @click="exRecord">执行记录</el-button>
                  </el-col>
                </el-row>
              </el-col>
            </el-form>
          </el-row>
        </el-col>
      </el-row>
    
    </div>
  <!-- 定价执行监控页面 --------------------------- -->
    <expricing-monitor
      v-if="exPricingShow === 'expricingMonitor'"
      ref="expricingMonitorPage"
      :monitorForm="monitorForm"
      :exPricingShow="exPricingShow"
     @toCatDetail="toCatDetail"
      @catSubTask ="catSubTask"
      @closeExMonitor="closeExMonitor"
    ></expricing-monitor>
      <!-- 定价执行监控页面  结束--------------------------- -->

      <!-- 执行记录页面 --------------------------- -->

    <expricing-record 
    v-if="exPricingShow === 'expricingRecord'"
    ref="recordTaskForm" 
    :recordTaskCode="recordTaskCode"
    :exPricingShow="exPricingShow"
     @toSubRecord ="catSubTask"
     @closeExMonitor="closeExMonitor"
    />

    <!-- 定价任务监控中的 查看结果 -->
        <monitor-cat-detail
        v-if="exPricingShow === 'monitorCatDetail'"
         :pricingCode="enginePricingCode"
         @toExMonitor="exmonitor"
        ></monitor-cat-detail>


    <!-- 定价任务监控中的 查看结果 -->


    <!-- 定价执行监控-------子任务页面 -->
    <exp-Sub-record
      v-if="exPricingShow === 'subRecordMonitor'"
      ref="recordSubForm"
      :subRecordFrom="recordForm"
      @toExecuteTask="exRecord"
      @toEngineTask ="toEngineTask"
      @closeExMonitor="closeExMonitor"
    />
    <!-- 定价执行监控子任务页面 结束 --------------------------- -->

    <!-- 异常定价引擎任务 -->

    <engine-task 
    v-if="exPricingShow === 'exPricingEngineTask'"
    ref="engineTaskRef"
    :enginePricingCode ="enginePricingCode"
     @toBlockDetail="toBlockDetail"
     @toExecuteTask="exRecord"
     @catSubTask ="catSubTask"
     @closeExMonitor="closeExMonitor"
    >
    </engine-task>

     <!-- 异常定价引擎任务 -->

       <!-- 异常定价引擎任务==>查看结果 -->
       <engine-cat-Detail
       v-if="exPricingShow === 'engineCatDetail'"
       :blockId="blockId"
       @toExEngineTask="toEngineTask"
       @closeExMonitor="closeExMonitor"
       >
       </engine-cat-Detail>



  </div>
</template>

<script>
import moment from "moment";
import { expricing } from "@/api/index";
//异常监控
import expricingMonitor from "./expricing_monitor";
//异常记录
import expricingRecord from "./exPricingTask_record";
//子任务
import expSubRecord from "./exPricingTask_subRecord";
//定价引擎任务
import engineTask from "./exPricing_engineTask"
//监控页面的查看结果
import monitorCatDetail from "./expricing_monitorCatDetail"

//监控页面的查看结果
import engineCatDetail from "./expricing_engineCatDetail"

export default {
      //引入组件
  components: {
    expricingMonitor,
    expricingRecord,
    expSubRecord,
    engineTask,
    monitorCatDetail,
    engineCatDetail
  },
  data() {
    return {
      //页面显示
      exPricingShow: "expricingIndex",
      //form表单的数据
      saveForm: {
        taskCode: "",
        scene: {}
      },
      saveFormRules: {
        taskName: [{ required: true, message: "任务名称", trigger: "blur" }],
        startDataDate: [
          { required: true, message: "请选择开始时间", trigger: "blur" }
        ],
        endDataDate: [
          { required: true, message: "请选择结束时间", trigger: "blur" }
        ]
      },
      executebutton: false,
      //执行定价监控数据
      monitortitleName: "异常定价监控",
      monitorDi: false,
      //传到子组件的值
      monitorForm: {},
      //执行记录的定价编码
      recordTaskCode:"",
      //子任务页面
      recordForm:{},
      //引擎定价任务
      enginePricingCode:"",
      //引擎任务 ==> 查看结果 传入参数
      blockId:"",
    
    };
  },
  //数据的组合计算
  computed: {},
  //生命钩子
  created() {
    this.init();
  },
  mounted() {},
  //监视数据变化
  watch: {},
  //方法区
  methods: {
    init() {
      expricing.findAll().then(res => {
        if (res.code == 200) {
          this.saveForm = res.data;
          this.$set(this.saveForm, "taskName", "异常定价任务");
          console.log(this.saveForm, "异常定价数据");
        }
      });
    },
    execute() {
      //防止二次点击  让按钮不可用
      this.executebutton = true;
      //校验数据是否存在
      this.$refs.expricingForm.validate(valid => {
        if (valid) {
          let params = {
            endDataDate: this.saveForm.endDataDate,
            startDataDate: this.saveForm.startDataDate,
            taskCode: this.saveForm.taskCode,
            taskName: this.saveForm.taskName
          };
          expricing.execute(params).then(res => {
            if (res.code == 200) {
              if (res.data != null && res.data.success) {
                this.$message.success(res.data.message);
              } else if (res.data != null && !res.data.success) {
                this.$message.error(res.data.message);
              } else {
                this.$message.success(res.message);
              }
            } else {
              this.$message.error(res.message);
            }
            this.executebutton = false;
          });
        } else {
          this.executebutton = false;
        }
      });
    },
    exmonitor() {
      //跳转执行监控页面 查询数据
      expricing.toMonitor().then(res => {
        if (res.code == 200) {
          this.monitorForm = {
            taskCode: this.saveForm.taskCode,
            taskName: this.saveForm.taskName,
            pricingCode: res.data.pricingRecord.pricingCode,
            dataDate: moment(res.data.pricingRecord.dataDate).format("YYYY-MM-DD") ,
            sceneName: res.data.scene.sceneName,
            versionNum: res.data.scene.versionNum,
            affirm: 0,
            refreshRate: "100"
          };
          console.log( this.monitorForm ," this.monitorForm 111")
          this.exPricingShow = "expricingMonitor";
        } else {
          this.$message.error(res.message);
        }
      });
    },
    //跳转执行记录
    exRecord(){
         this.recordTaskCode =this.saveForm.taskCode;
         this.exPricingShow = "expricingRecord";
    },
    //监控页面 -- 查看结果
    toCatDetail(val){
        this.enginePricingCode =val;
        this.exPricingShow = 'monitorCatDetail';

    },
    //返回首页
    closeExMonitor() {
      this.exPricingShow = "expricingIndex"; 
    },
    //查看子任务数据
    catSubTask(val){
   
    this.recordForm = this.$clone(val);
     console.log(this.recordForm,"子任务传过来的数据")
     this.exPricingShow = "subRecordMonitor"; 
    
    },
    //访问定价引擎任务
    toEngineTask(val){
        //首先参数赋值
        this.enginePricingCode  = val;
        console.log(this.enginePricingCode,"子任务跳转定价引擎")
        this.exPricingShow ="exPricingEngineTask";
    },
    //引擎任务==>查看结果
    toBlockDetail(val){
        this.blockId =val;
        this.exPricingShow ='engineCatDetail';

    }
  }
};
</script>

<style lang="scss" scoped>
</style>
